<template>
  <div class="login">
    <div class="box">
      <div class="name">iHRM后台登录系统</div>
      <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
          <el-form-item prop="username">
            <el-input prefix-icon="el-icon-user-solid" placeholder="username" v-model="ruleForm.username"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              prefix-icon="el-icon-s-order"
              placeholder="password"
              v-model="ruleForm.password"
              show-password
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')" class="login-btn">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="footer">还没有账号？立即注册</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          { required: true, message: "用户名不能小于6位", trigger: "blur" },
          { min: 6, message: "用户名不能小于6位", trigger: "blur" }
        ],
        password: [
          { required: true, message: "密码不能小于6位", trigger: "blur" },
          { min: 6, message: "密码不能小于6位", trigger: "blur" }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.push("/home")
        } else {
          console.log("error submit!!")
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background: url(http://ihrm-java.itheima.net/static/img/login.c75bab6.jpg);
  display: flex;
  justify-content: center;
  align-items: center;
  .box {
    width: 400px;
    .name {
      color: #fff;
      font-size: 45px;
      margin-bottom: 30px;
    }
    .footer {
      color: #fff;
      text-align: center;
    }
		.login-btn{
			width: 400px;
			height: 60px;
		}
  }
}
</style>
